<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__LAYUIMINI__/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="__LAYUIMINI__/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <link rel="stylesheet" href="__LAYUIMINI__/css/public.css" media="all">
</head>

<body>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <!-- layui-form-pane 方框式表单 -->
            <form class="layui-form layui-form-pane" action="" lay-filter="example">
                <div class="layui-form-item">
                    <label class="layui-form-label">上级权限</label>
                    <div class="layui-input-block">
                        <select name="pid" lay-verify="required" lay-search="">
                            <option value="0" {if condition="$one.pid==0"} selected {/if}>顶级菜单</option>
                            {volist name="$menuList" id="vo"}
                                <option value="{$vo.id}" {if condition="$one.pid==$vo.id"} selected {/if} {if condition="$one.id==$vo.id"} disabled="" {/if} >{$vo.title}</option>
                                {if condition="$vo.child"}
                                    {volist name="$vo.child" id="vo2"}
                                    <option value="{$vo2.id}" {if condition="$one.pid==$vo2.id"} selected {/if} {if condition="$one.id==$vo2.id"} disabled="" {/if}>----{$vo2.title}</option>
                                        {if condition="$vo2.child"}
                                        {volist name="$vo2.child" id="vo3"}
                                        <option value="{$vo3.id}" {if condition="$one.pid==$vo3.id"} selected {/if} {if condition="$one.id==$vo3.id"} disabled="" {/if}>--------{$vo3.title}</option>
                                        {/volist}
                                        {/if}
                                    {/volist}
                                {/if}
                            {/volist}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">权限名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="title" lay-verify="required" autocomplete="off" placeholder="请输入名称"
                            class="layui-input" value="{$one['title']}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">路由地址</label>
                    <div class="layui-input-block">
                        <input type="text" name="href" autocomplete="off" placeholder="请输入路由" class="layui-input" value="{$one['href']}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">排序</label>
                    <div class="layui-input-block">
                        <input type="number" name="sort" autocomplete="off" class="layui-input" value="{$one['sort']}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">选择图标</label>
                    <div class="layui-input-block">
                        <input type="text" name="icon" id="iconPicker" lay-filter="iconPicker" class="hide" value="{$one['icon']}">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <input type="checkbox" {if condition="$one.status==1"} checked=""{/if} name="status" lay-skin="switch" lay-filter="switchTest"
                            lay-text="正常|关闭">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">类型</label>
                    <div class="layui-input-block">
                        <input type="radio" name="type" value="1" title="菜单" {if condition="$one.type==1"} checked=""{/if} >
                        <input type="radio" name="type" value="2" title="权限" {if condition="$one.type==2"} checked=""{/if} >
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">打开方式</label>
                    <div class="layui-input-block">
                        <input type="radio" name="target" value="_self" title="当前" {if condition="$one.target=='_self'"} checked=""{/if} >
                        <input type="radio" name="target" value="_blank" title="新窗口" {if condition="$one.target=='_blank'"} checked=""{/if}>
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <textarea placeholder="请输入内容" class="layui-textarea" name="desc">{$one.desc}</textarea>
                    </div>
                </div>
                <input type="hidden" value="{$one['id']}" name="id">
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                        <!-- <button type="reset" class="layui-btn layui-btn-primary">重置</button> -->
                    </div>
                </div>
            </form>
        </div>
    </div>

    <script src="__LAYUIMINI__/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script src="__LAYUIMINI__/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
    <script>
        layui.use(['form', 'iconPickerFa'], function () {
            var form = layui.form,
                iconPickerFa = layui.iconPickerFa,
                $ = layui.$,
                layer = layui.layer;

            iconPickerFa.render({
                // 选择器，推荐使用input
                elem: '#iconPicker',
                // fa 图标接口
                url: "__LAYUIMINI__/lib/font-awesome-4.7.0/less/variables.less",
                // 是否开启搜索：true/false，默认true
                search: true,
                // 是否开启分页：true/false，默认true
                page: true,
                // 每页显示数量，默认12
                limit: 16,
                // 点击回调
                click: function (data) {
                    console.log(data);
                },
                // 渲染成功后的回调
                success: function (d) {
                    console.log(d);
                }
            });
            //监听指定开关
            form.on('switch(switchTest)', function (data) {

            });

            //监听提交
            form.on('submit(demo1)', function (data) {
                $.ajax({
                    type: "post",
                    url: "saveMenu",
                    data: data.field,
                    dataType: "json",
                    success: function (res) {
                        if (res.code == 1) {
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            // parent.layer.close(index); //再执行关闭 
                            // 关闭后调用
                            layer.msg(res.msg)
                            setTimeout(function () {
                                parent.layer.close(index);

                            }, 500)
                        } else {
                            layer.msg(res.msg)
                        }


                    }
                });
                return false;
            });
        });
    </script>

</body>

</html>